from flask import render_template
from app.forms import UploadForm, photos
from app.models import run_inference
from app import app

import os

@app.route('/')
@app.route('/infe', methods=['GET', 'POST'])
def upload_file():
  form = UploadForm()
  caption=['test']
  if form.validate_on_submit():
    filename = photos.save(form.photo.data)
    file_url = photos.url(filename)
    caption = run_inference(app.config['UPLOADED_PHOTOS_DEST'] + '/' + filename)	
  else:
    file_url = None
  
  return render_template('index.html', form=form, file_url=file_url, caption=caption)
	
